
// ignore_for_file: use_key_in_widget_constructors

import 'package:cupertino_store/product_row_item.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';

import 'model/app_state_model.dart';

// Consumer在Flutter中是指一个能够“消费”数据的Widget，它可以监听一个特定的数据源，并在数据源发生变化时自动更新UI。Consumer通常与Provider一起使用，Provider负责管理数据源，而Consumer则订阅这个数据源，当数据源发生变化时，它会自动重新构建UI。

class ProductListTab extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      child: Consumer<AppStateModel>(
      builder: (context, model, child) {
        final products = model.getProducts();
        return CustomScrollView(
          semanticChildCount: products.length,
          slivers: [
           const CupertinoSliverNavigationBar(
              largeTitle: Text('Cupertino Store'),
            ),
            SliverSafeArea(      // BEGINNING OF NEW CONTENT
               top: false,
               minimum: const EdgeInsets.only(top: 8),
               sliver: SliverList(
                 delegate: SliverChildBuilderDelegate(
                   (context, index) {
                     if (index < products.length) {
                       return ProductRowItem(
                         index: index,
                         product: products[index],
                         lastItem: index == products.length - 1,
                       );
                     }
                     return null;
                   },
                 ),
               ),
             )                  // END OF NEW CONTENT
          ],
        );
      },
    )
    );
  }
}

